package com.itheima.health.config;

import com.itheima.health.job.CleanImgageJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.text.ParseException;

@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail getCleanImageDetail(){
        JobDetail cleanImageDetail = JobBuilder.newJob(CleanImgageJob.class)
                .withIdentity("cleanImageDetail")
                .storeDurably(true)
                .build();
        return cleanImageDetail;
    }
    @Bean
    public Trigger scheduleJobTrigger(@Qualifier("getCleanImageDetail") JobDetail jobDetail) throws ParseException {
        Trigger cleanImageJobTrigger = TriggerBuilder.newTrigger()
                .forJob(jobDetail)
                .withIdentity("cleanImageJobTrigger")
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0/10 * * * ? "))
                .build();
        return cleanImageJobTrigger;
    }
}
